module.exports = function ($scope, $modalInstance, $resource, $modal, item, flag, toaster){

    init();
    function init(){
        $scope.info = flag ? {'flag': true} : angular.copy(item);
        console.log($scope.info.type);
       if($scope.info.type == 1 ){
        $scope.info.typename = '旅游法规信息分类';
        console.log($scope.info.typename);
       }else if($scope.info.type == 2 ){
        $scope.info.typename = '旅游企业制度信息分类';
       }
       else if($scope.info.type == 3 ){
        $scope.info.typename = '公示曝光模板类型';
       }
       else if($scope.info.type == 4 ){
        $scope.info.typename = '题库类型';
       }
    }
    //保存
    $scope.save = function (){
        
        if($scope.info.key == undefined){
            toaster.error({title: '', body: '请输入类型名称！'});
          return;
        }
        if($scope.info.value == undefined){
            toaster.error({title: '', body: '请输入类型数值！'});
          return;
        }
        var para = {
            'type':  $scope.info.type,
            'id' :  $scope.info.id,
            'key' : $scope.info.key,
            'value' : $scope.info.value
        }
        $resource('/api/as/goc/pelawinfo/savetype', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
   
    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }

};